/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main.controller;

/**
 *
 * @author Ariman
 */
import javax.faces.component.UIInput;
import javax.faces.component.UIPanel;
import main.models.Login;
import main.models.Player;
import main.DBmodels.User;
import main.models.Hall;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ManagedProperty;


@ManagedBean
@RequestScoped
public class LoginController {

    @ManagedProperty (value = "#{login}")
    private Login login;
    private UIPanel errorPanel;
    private UIInput nameInput;
    private UIInput passInput;
    @ManagedProperty (value = "#{player}")
    private Player player;
    @ManagedProperty (value = "#{hall}")
    private Hall hall;

    public LoginController() {
    }
    
    public String validate() {
        try {
            User user = login.logining();
            player.setUID(user.getUID());
            player.setName(user.getLogin());
            errorPanel.setRendered(false);
            nameInput.setValue(login.getLoginName());
            passInput.setValue(login.getLoginPass());
            hall.addPlayer(player);
            return "success";
        } catch (Exception ex) {
            errorPanel.setRendered(true);
        }
        return "unsuccess";
    }
    public String registration(){
        return login.registration();
    }

    public UIPanel getErrorPanel() {
        return errorPanel;
    }

    public void setErrorPanel(UIPanel errorPanel) {
        this.errorPanel = errorPanel;
    }

    public Login getLogin() {
        return login;
    }

    public void setLogin(Login login) {
        this.login = login;
    }

    public UIInput getNameInput() {
        return nameInput;
    }

    public void setNameInput(UIInput nameInput) {
        this.nameInput = nameInput;
    }

    public UIInput getPassInput() {
        return passInput;
    }

    public void setPassInput(UIInput passInput) {
        this.passInput = passInput;
    }

    public Player getPlayer() {
        return player;
    }

    public void setPlayer(Player player) {
        this.player = player;
    }

    public Hall getHall() {
        return hall;
    }

    public void setHall(Hall hall) {
        this.hall = hall;
    }
    
}